﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.BusinessObject.Resource;
using log4net;
using Jalal.Library.Utility;
using System.Collections.Generic;

public partial class Admin_Resource_Trailer_EditMoreDownloadFormat : AdminBasePage
{
    private int Id
    {
        get
        {
            if (ViewState["Id"] == null)
                ViewState["Id"] = 0;
            return (int)ViewState["Id"];
        }
        set { ViewState["Id"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Id = 0;
            if (!string.IsNullOrEmpty(Request.QueryString["id"]) && int.TryParse(Request.QueryString["id"], out id))
            {
                Id = id;
                LoadData();
            }
            else
                Response.Redirect(CustomSiteMap.Trailers);

            InitControls();
        }
    }

    private void InitControls()
    {
        btnDelete.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete?');");
    }

    private void LoadData()
    {
        TrailerFormat trailerFormat = TrailerFormat.GetTrailerFormatByTrailerFormatId(Id);
        hlkDownloadVideo.NavigateUrl = trailerFormat.FileUrl;
        ddlFormat.SelectedValue = trailerFormat.VideoFormat;
    }

    protected void Create_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            try
            {

            }
            catch (Exception ex)
            {
                // Write the log into handled exception list
                ILog log = LogHelper.GetHandledFileLogger("EditMoreDownloadFormat");
                if (log.IsErrorEnabled)
                    log.Error("Failed to update download format to trailer", ex);

                uccResponse.SetFailMessage("There was a problem in updating trailer format");
            }
        }
    }

    protected void Delete_Click(object sender, EventArgs e)
    {
        if (TrailerFormat.Delete(new List<int> { Id }))
            Response.Redirect(CustomSiteMap.Trailers);
        else
            uccResponse.SetFailMessage("Failed to delete format");
    }
}
